--[[------------------------------------------UI管理器------------------------------------------------------]]--
UIManager = UIManager or {};


--[[------------------------------------------配置数据------------------------------------------------------]]--
-- change MainUI SettlementUI to MainUIClassPath SettlementUI
UIManager.MainUIClassPath = UGCMapInfoLib.GetRootLongPackagePath().. "Asset/UI/UIBP_MainUI.UIBP_MainUI_C";
--UIManager.SettlementUIClassPath = UGCMapInfoLib.GetRootLongPackagePath().. "Asset/UI/UIBP/AC_Result_UIBP.AC_Result_UIBP_C";
UIManager.GuideUIClassPath = UGCMapInfoLib.GetRootLongPackagePath().. "Asset/UI/UIBP_HowToPlay.UIBP_HowToPlay_C";

--[[------------------------------------------动态数据------------------------------------------------------]]--
UIManager.MainUI = nil;
UIManager.SettlementUI = nil;

--[[--------------------------------------------逻辑--------------------------------------------------------]]--
function UIManager:Init()
	print("UIManager:Init")
	self:InitBaseUI();
	self:CreateMainUI();
    self:CreateStartGuideUI();
end

function UIManager:InitBaseUI()
	print("UIManager:InitBaseUI")

    --TODO:搞清楚下面在干嘛
	-- 接口有问题，IOS上无法正常获取到
    -- local MainControlPanel = UGCWidgetManagerSystem.GetMainUI();
    local MainControlPanel = GameBusinessManager.GetWidgetFromName(ingame, "MainControlPanelTochButton_C");
    
    if MainControlPanel ~= nil then
        -- 隐藏和平的主界面UI、射击UI，保留设置和聊天按钮
        -- UGCWidgetManagerSystem.AddWidgetHiddenLayer(MainControlPanel.MainControlBaseUI)
        -- TODO: 应增加一些调整和平UI的接口
        local MainControlBaseUI = MainControlPanel.MainControlBaseUI;
        MainControlBaseUI.NavigatorPanel:AddAdvancedCollapsedCount(1);
        MainControlBaseUI.Image_0:AddAdvancedCollapsedCount(1);
        MainControlBaseUI.CanvasPanel_5:AddAdvancedCollapsedCount(1);
        MainControlBaseUI.CanvasPanel_FreeCamera:AddAdvancedCollapsedCount(1);
        MainControlBaseUI.InvalidationBox_TipsContainer:AddAdvancedCollapsedCount(1);
        MainControlBaseUI.InvalidationBox_3:AddAdvancedCollapsedCount(1);
        MainControlBaseUI.CanvasPanel_MiniMapAndSetting:AddAdvancedCollapsedCount(1);
        -- MainControlBaseUI.Canvas_Speaker:AddAdvancedCollapsedCount(1);
        -- MainControlBaseUI.Canvas_Microphone:AddAdvancedCollapsedCount(1);
        MainControlBaseUI.Emote_SwimingControl:AddAdvancedCollapsedCount(1);
        MainControlBaseUI.SignalReceivingAreaTIPS_UIBP:AddAdvancedCollapsedCount(1);
        MainControlBaseUI.Border_TopPlatformTipsColor:AddAdvancedCollapsedCount(1);
        MainControlBaseUI.BackPackPickUpPanel_BP_0:AddAdvancedCollapsedCount(1);
        MainControlBaseUI.InvalidationBox_GM:AddAdvancedCollapsedCount(1);
        MainControlBaseUI.PlayerInfoSocket:AddAdvancedCollapsedCount(1);
        MainControlBaseUI.IsNeedTeamPanel = false;

        -- UGCWidgetManagerSystem.AddWidgetHiddenLayer(MainControlPanel.ShootingUIPanel)
        -- 聊天面板在战斗UI中，需要显示
        local ShootingUIPanel = MainControlPanel.ShootingUIPanel;
        ShootingUIPanel.InvalidationBox_2:AddAdvancedCollapsedCount(1);
        ShootingUIPanel.CanvasPanel_16:AddAdvancedCollapsedCount(1);
        ShootingUIPanel.NewbieGuideCanvas:AddAdvancedCollapsedCount(1);
        ShootingUIPanel.Fade:AddAdvancedCollapsedCount(1);
    else
        print("Error: AeroplaneChessUIManager:InitBaseUI MainControlPanel == nil!");
    end
end

function UIManager:CreateMainUI( )
	print("UIManager:CreateMainUI")
    local MainUIClass = UE.LoadClass(UIManager.MainUIClassPath);
    if MainUIClass == nil then
        print(string.format("Error: UIManager:CreateMainUI MainUIClass[%s] == nil!", UIManager.MainUIClassPath));
        return false;
    end

    local PlayerController = GameplayStatics.GetPlayerController(UGCGameSystem.GameState, 0);
    if PlayerController == nil then
        print("Error:UIManager:CreateMainUI PlayerController == nil!");
        return false;
    end

    self.MainUI = UserWidget.NewWidgetObjectBP(PlayerController, MainUIClass);
    if self.MainUI == nil then
        print("Error: UIManager:CreateMainUI MainUI == nil!");
        return false;
    end

     -- 这里不知为何会报错，暂时用下面这个
    -- UGCWidgetManagerSystem.AddChildToTochButton(self.MainUI)
    local TochButton = GameBusinessManager.GetWidgetFromName(ingame, "MainControlPanelTochButton_C");
    if TochButton ~= nil then
        -- 添加自定义按钮功能
        UIUtil.AttachTo(TochButton:GetWidgetFromName("CanvasPanel_IPX"), self.MainUI, 0, { Minimum = { X = 0, Y = 0 }, Maximum = { X = 1, Y = 1 } }, { Left = 0, Right = -1.5, Bottom = 0, Top = 0 })
        CustomizeUtils.ApplyAllUGCButtonsSetting(self.MainUI)
    else
        print("Error: TochButton is nil")
    end

    return UIManager.MainUI;
end

-- 创建并显示新手指引UI
function UIManager:CreateStartGuideUI()
	print("UIManager:CreateStartGuideUI")

    local GuideUIClass = UE.LoadClass(UIManager.GuideUIClassPath);
    if GuideUIClass == nil then
        print(string.format("Error: UIManager:CreateStartGuideUI GuideUIClass[%s] == nil!", UIManager.GuideUIClassPath));
        return false;
    end

    local PlayerController = GameplayStatics.GetPlayerController(UGCGameSystem.GameState, 0);
    if PlayerController == nil then
        print("Error: UIManager:CreateStartGuideUI PlayerController == nil!");
        return false;
    end

    self.StartGuideUI = UserWidget.NewWidgetObjectBP(PlayerController, GuideUIClass);
    if self.StartGuideUI == nil then
        print("Error: UIManager:CreateStartGuideUI StartGuideUI == nil!");
        return false;
    end

    self.StartGuideUI:AddToViewport(10051);
end


